package org.example.service;

import org.example.dao.GuideDao;
import org.example.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

@Service
// 这个注解表示这是一个服务类，并且在事务中进行操作，如果出现异常，则回滚事务
@Transactional(rollbackFor = Exception.class)
public class GuideService {
    @Autowired
    private GuideDao guideDao;

    public List<Hotel> getHotelList() {
        List<Hotel> hotelList = guideDao.getHotelList();
        for (Hotel hotel : hotelList) {
            String[] featuresArray = hotel.getFeaturesArray().stream().map(Features::getName).toArray(String[]::new);
            hotel.setFeatures(featuresArray);
        }
        return hotelList;
    }

    public List<Emergency> getEmergencyList() {
        return guideDao.getEmergencyList();
    }

    public List<Tips> getTipsList() {
        return guideDao.getTipsList();
    }

    public List<Traffic> externalTraffic() {
        return guideDao.externalTraffic();
    }

    public List<Traffic> internalTraffic() {
        return guideDao.internalTraffic();
    }
}
